#!/usr/bin/env bash
# 软件安装子菜单

software_menu_show() {
  clear
  echo -e "${YELLOW}【软件安装】${RESET}"
  echo -e "  ${GREEN}1.${RESET} 安装必备工具 (vim, unzip, lsof)"
  echo -e "  ${GREEN}2.${RESET} 安装网络工具 (curl, wget, net-tools, traceroute)"
  echo -e "  ${GREEN}3.${RESET} 安装开发工具 (git, build-essential, python3-pip)"
  echo -e "  ${GREEN}4.${RESET} 安装 Docker & docker-compose"
  echo -e "  ${GREEN}5.${RESET} 安装 Node.js & npm (LTS)"
  echo -e "  ${GREEN}6.${RESET} 安装 Nginx"
  echo -e "  ${GREEN}7.${RESET} 安装 OpenSSH Server / Fail2ban"
  echo -e "  ${GREEN}8.${RESET} 安装 gost (Go-Gost v3)"
  echo -e "  ${GREEN}9.${RESET} 安装 3x-ui"
  echo -e "  ${GREEN}10.${RESET} 安装 x-ui"
  echo ""
  echo -e "  ${GREEN}0.${RESET} 返回主菜单"
}

software_menu_loop() {
  while true; do
    software_menu_show
    read -rp "请选择 [0-10]: " a
    case "$a" in
      1)  pick "安装必备工具";           run_or_stub install_basic_tools ;;
      2)  pick "安装网络工具";           run_or_stub install_network_tools ;;
      3)  pick "安装开发工具";           run_or_stub install_dev_tools ;;
      4)  pick "安装 Docker & compose";  run_or_stub install_docker_and_compose ;;
      5)  pick "安装 Node.js & npm";     run_or_stub install_nodejs_and_npm ;;
      6)  pick "安装 Nginx";             run_or_stub install_nginx_and_enable ;;
      7)  pick "安装 OpenSSH/Fail2ban";  run_or_stub install_openssh_and_fail2ban ;;
      8)  pick "安装 gost (Go-Gost v3)"; run_or_stub install_gost ;;
      9)  pick "安装 3x-ui";             run_or_stub install_3xui ;;
      10) pick "安装 x-ui";              run_or_stub install_xui ;;
      0)  break ;;
      *)  echo -e "${RED}${BOLD}❌ 无效输入，请重试${RESET}" ;;
    esac
    [[ "$a" != 0 ]] && read -rp "按回车键返回上级..."
  done
}
